package com.tc.dispatch.csservice.util;

import java.util.Comparator;
import com.tc.dispatch.gsalgorithm.spec.spec;
import com.tc.dispatch.gsalgorithm.spec.parse;
import com.tc.dispatch.gsservice.action.GSSimilary;
import com.tc.dispatch.gsservice.model.OrderSumMain;
import com.tc.dispatch.gsalgorithm.exception.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2008</p>
 * <p>Company: zju</p>
 * @author jakcyjia
 * @version 1.0
 */

public class OSMComparator implements Comparator {
  private spec _spec;

  public OSMComparator(spec _spec) {
    this._spec=_spec;
  }
  public int compare(Object parm1, Object parm2) {
    OrderSumMain osm1=(OrderSumMain)parm1;
    OrderSumMain osm2=(OrderSumMain)parm2;
    spec spec1=parse.parseSpec(osm1.getSpec());
    spec spec2=parse.parseSpec(osm2.getSpec());
    try {
      if (GSSimilary.calcSimilary(_spec, spec1).floatValue() >
          GSSimilary.calcSimilary(_spec, spec2).floatValue()) {
        return 1;
      }
      else {
        return -1;
      }
    }
    catch (AlgorithmException ex) {
      System.out.println("AlgorithmException is found:"+ex.getMessage());
      return -1;
    }
  }

}